<?php
namespace app\helpers;

/**
 * 接口返回状态码管理
 *
 */
class ApiCode{

    const REGISTER_VERIFY_TYPE = 1;
    const LOGIN_VERIFY_TYPE = 2;
    const API_CODE_ERROR = '9999';
    const WANG_JIN_SUC = "0000";
    const COMMMON_ERROR_CODE = "1005";
    const API_OK         = '200';
    //服务器错误
    const SERVICE_DATA_EXCEPTION = '5000';
    const API_ABNORMAL = '5002';
    const NOT_LOGIN = '5003';
    const USER_INFO_NULL = '5004';
    const NOT_RECEIVE = '5005';
    const NOT_SUBMIT = '5006';
    const ORDER_FAILED = '5007';
    const FIRST_LOGIN = '5008';
    const NOT_BIND_CARD = '5009';
    const FIRST_JOIN = '5010';
    const REGISTER_ERROR = '5011';
    const REGISTER_SUCC = '5012';
    const REGISTER_ACTIVE_ERROR = '5013';
    const MOBILE_ERROR = '5014';
    const EMAIL_ERROR = '5015';
    const USER_INFO_DIFFRENT = '5016';
    const VERIFY_CODE_ERROR = '5017';
    const PARAM_NULL = '4002';
    const IS_USER = '4049';
    const CODE_ERROR = '4050';
    const OPRATIONE_CODE_ERROR = '4051';
    const REQUEST_METHOD_ERROR = '4052';
    const REQUEST_PARAM_NULL = '4053';
    const UNDFINDED      = '-9999';
    const NO_DEBIT_CARD = '6001';
    const GROUP_NOT_EXSITS = '6002';

    //市政一卡通  从10000开始定义
    const OCARD_AID_ERROR = '10001';

    //三方联合登录 3000 开始
    const THIRD_LOGIN_SIGN_ERROR = '3000';
    const THIRD_LOGIN_AUTH_ERROR = '3101';
    const THIRD_LOGIN_AUTH_EXPIRED = '3102';

    //通用  fileupload 未接收到上传文件
    const FILE_NOT_FOUND = '3201';
    //共享盒子
    const DEVICE_EXIST = '3301';

    //迁入飞凡通
    //login token 获取用户信息失败
    const LOGIN_TOKEN_ERROR = '4601';


    public static $messages = [

        '-9999' => '未知',
        '9999' => '接口返回解析错误',

        '200'  => '成功',
        '5001' => '系统错误',
        '5002' => '调用服务异常',
        '3003' => '数据库异常',
        '3004' => '无效请求',
        '3005' => '运行时异常',
        '4001' => '参数校验失败',
        '4002' => '参数为空',
        '4050' => '验证码错误',
        '4100' => '信息安全失败',
        '4049' => '用户已注册',
        '4051' => '合作方唯一标识被篡改',
        '4052' => '请求方法被篡改',
        '4053' => '参数%s不能为空',
        '5003' => '未登录状态',
        '5004' => '未获取到用户信息',
        '5005' => '抱歉，您填写的投保人信息未能通过审核，无法领取礼包',
        '5006' => '抱歉，您填写的投保人资料无法提交',
        '5008' => '对不起，请您先下载飞凡app并做首次登陆',
        '5009' => '您还未绑定银行卡，暂不能领取；打开“飞凡app-飞凡通-卡管家”绑定银行卡',
        '5010' => '抱歉，活动期内首次绑卡用户才能参加活动',
        '5011' => '对不起，注册会员失败',
        '5012' => '注册成功，请完成绑定银行卡再领取',
        '5013' => '会员激活失败',
        '5014' => '手机号码格式错误',
        '5015' => '邮箱地址格式错误',
        '5016' => '会员信息不一致',
        '5017' => '验证码错误',
        '6001' => '您尚未绑定借记卡',
        '6002' => 'GROUP分组不存在',

        //服务异常
        '5000' => '服务返回数据异常',

        //市政一卡通
        '10001' => '应用不合法',

        //三方联合登录
        '3000'  => '签名认证失败',
        '3101'  => '非法操作,授权失败',
        '3102'  => '授权过期',
        //FILEUPLAOD
        '3201'  => '未接收到上传文件',
        //共享盒子
        '3301'  => '设备已存在',

        //login token 获取用户信息失败
        '4601'  => 'loginToken获取用户信息失败!',
    ];


    /**
     * 翻译接口返回代码,代码翻译不存在,使用接口方发送的信息
     * @param string $code
     */
    public static function trans($code,$msg = ''){
        $code = ''. $code;
        return isset(self::$messages[$code]) ? self::$messages[$code] : $msg;
    }

    /**
     * 以业态返回的message字段为主
     * @param string $code
     */
    public static function transUseService($code,$msg = ''){
        $code = ''. $code;
        return $msg ?: (isset(self::$messages[$code]) ? self::$messages[$code] : '');
    }
}
